﻿

--#include "data\functions\Activity\Dart\ApplyDartCommon.lua" once
--#include "data\functions\Activity\PublicTest.lua" once

--定时器ID定在文件：ActorTimerIds.lua


--特定定时器对应的脚本回调
TimerFunc = {}
TimerFunc[1] = function(sysarg)
	
	local var = Actor.getStaticVar(sysarg)
	if not var.AlchemyTime then
		return
	end
	
	if not EquipMelting then return end
	local config = EquipMelting.EquipAlchemy
	
	var.AlchemyTime = var.AlchemyTime - 1
	if var.AlchemyTime <= 0 then
		Actor.sendTipmsg(sysarg,Lang.ScriptTips.zf243,ttFlyTip)
		Actor.deleteTimer(sysarg,ActorTimerIds.Alchemy)
		return
	end
end

TimerFunc[2] = function(sysarg)
	local dVar = Actor.getDyanmicVar(sysarg)
	local svar = Actor.getStaticVar(sysarg)

	if not dVar.Timer then dVar.Timer = 0 end

	if svar.ybstate == 1 then
		local monster = Actor.getEntity(svar.bcHandle)
		local playerX,playerY = Actor.getEntityPosition(sysarg,0,0)
		local monsterX,monsterY = Actor.getEntityPosition(monster,0,0)

		monsterX = monsterX - playerX
		monsterY = monsterY - monsterY
		
		local Distance = (monsterX*monsterX) + (monsterY*monsterY)

		if Distance > (10*10) then
			if dVar.Timer % 10 == 0 then
				local monsterX2,monsterY2 = Actor.getEntityPosition(monster,0,0)
				local nowSceneName = Actor.getSceneName(monster, 0, 0)
				Actor.sendTipmsg(sysarg,string.format(Lang.Activity.k00048,nowSceneName,monsterX2,monsterY2), ttFlyTip)
			end
		
			if dVar.Timer > 120 then
				dVar.Timer = nil
			end
			if dVar.Timer then
				dVar.Timer = dVar.Timer + 1
			end
		else
			if dVar.Timer > 0 then
				dVar.Timer = 0
			end
		end
	end
end

TimerFunc[3] = function(sysarg)	
	local dVar = Actor.getDyanmicVar(sysarg)
	if not dVar.TyrantsTimer then dVar.TyrantsTimer = 0 end
	dVar.TyrantsTimer = dVar.TyrantsTimer + TyrantsHeartConfig.interval
	if dVar.TyrantsTimer >= TyrantsHeartConfig.totalTime then
		dVar.TyrantsTimer = nil
		Actor.deleteTimer(sysarg,ActorTimerIds.Tuhaozhixin)
		return
	end

	local playerX,playerY = Actor.getEntityPosition(sysarg,0,0)
	local scenePtr = Actor.getScenePtr(sysarg)
	local nearPlayer = LuaHelp.getNearEntityListFromRange(scenePtr,playerX,playerY,4,4,0)
	if not nearPlayer then return end
	local nPlaCount = #nearPlayer
	if  nPlaCount - 1 <= 0 then return end
	if Actor.changeMoney(sysarg,mtBindCoin,-TyrantsHeartConfig.lostMoney*(nPlaCount - 1),GameLog.clConsumeBindCoin,Lang.LogTips.coin00006) == false then
		dVar.TyrantsTimer = nil
		Actor.deleteTimer(sysarg,ActorTimerIds.Tuhaozhixin)
		return
	end
	for k, plyPtr in pairs(nearPlayer or {}) do
		if plyPtr and not Actor.isDeath(plyPtr)  then
			if plyPtr ~= sysarg then
				Actor.changeMoney(plyPtr,mtBindCoin,TyrantsHeartConfig.getMoney,GameLog.cBossHeart,Lang.LogTips.coin00006)
			end
		end
	end
	
end

TimerFunc[4] = function(sysarg)
--[[ zhfy
	local dVar = Actor.getDyanmicVar(sysarg)
	if dVar.CFGCCD and System.getCurrMiniTime() >= dVar.CFGCCD+3600 then
		Actor.returnCity(sysarg)
	end
--]]
end	

TimerFunc[5] = function(sysarg)
	--[[
	local sVar = Actor.getStaticVar(sysarg)
	if sVar.avoidUpTime and sVar.avoidUpTime > 0 then
		sVar.avoidUpTime = sVar.avoidUpTime - 1
		if sVar.avoidUpTime <= 0 then
			local nCurLevel = Actor.getIntProperty(sysarg,PROP_ACTOR_AVOIDINJURY_LEVEL)
			Actor.setIntProperty(sysarg,PROP_ACTOR_AVOIDINJURY_EXP,0)
			Actor.setIntProperty(sysarg,PROP_ACTOR_AVOIDINJURY_LEVEL,nCurLevel+1)
			Actor.collectOperate(sysarg,0) -- 重新计算角色属性
			Actor.FullAvoid(sysarg)
			sVar.avoidUpTime = nil
			Actor.deleteTimer(sysarg,ActorTimerIds.AvoidUp)
			return
		end
	end
	]]
end	

TimerFunc[6] = function(sysarg)
	local sceneId = Actor.getSceneId(sysarg)
	local st = QiBingDuoBaoConfig.startTime
	local et = QiBingDuoBaoConfig.endTime
		
	if (sceneId == QiBingDuoBaoConfig.SceneId and System.isInTimeRange(st[1], st[2], st[3], et[1], et[2], et[3])) then		
		Actor.addExp(sysarg, QiBingDuoBaoConfig.exp, GameLog.cDuoBaoQiBingAward, 0, 1)
		if QiBingDuoBaoConfig.coin > 0 then
			Actor.changeMoney(sysarg, mtCoin, QiBingDuoBaoConfig.coin, GameLog.cDuoBaoQiBingAward, "DuoBao")			
		end
		System.broadcastTipmsg(string.format(Lang.Activity.qbdb0005,Actor.getName(sysarg)),2+128)
	else
		--print("No delete timer, here delete the timer")
		if Actor.hasTopTitle(sysarg,QiBingDuoBaoConfig.titleId) then
			--Actor.delTopTitle(sysarg,QiBingDuoBaoConfig.titleId)
			Actor.removeItem(sysarg,QiBingDuoBaoConfig.propId,1)
			Actor.addItem(sysarg,QiBingDuoBaoConfig.giftId,0,0,1,0,0,"",1)

			--local dVar = Actor.getDyanmicVar(sysarg)
			--if dVar.SpidTitle then
			--	Actor.addTopTitle(player,31)
			--end
		end
		Actor.exitActivityScene(sysarg)
		return 0
	end
end

TimerFunc[7] = function(sysarg)
	local cfg = PublicTestCfg.TitleCfg
	--if Actor.hasTopTitle(sysarg, cfg.titleId) then
	--	Actor.delTopTitle(sysarg, cfg.titleId)
	--end

	SendPublicTestTitleOver(sysarg)
	
	--[[
	local name = StringFromAwardType(cfg.consume.type)
	if name == nil then return 0 end
	
	local str = string.format("您的绝版称号{color;ffffff00;霸者天下}已经过期了，花费{color;FF00FF00;%d}%s可以继续使用{color;FF00FF00;%d}天", cfg.consume.count, name, cfg.validDay)
	Actor.messageBox(sysarg,0,0,str, "续费/publicTest_buyTitle,1", "以后再说吧/publicTest_buyTitle,0", NULL, 0)
	--]]
	
	-- 返回 0 则删除
	return 0
end

TimerFunc[8] = function(sysarg)
	wangling_exit_scene(sysarg)

	return 0 -- 返回 0 则删除定时器
end

TimerFunc[9] = function(sysarg)
	return on_garden_timer_cb(sysarg)
end

TimerFunc[10] = function(sysarg)
	return on_practice_room_timer_cb(sysarg)
end

TimerFunc[11] = function(sysarg)
	return on_challenge_fuben_timer_cb(sysarg)
end

TimerFunc[12] = function(sysarg)
	return on_challenge_fuben_refresh_monsters_timer_cb(sysarg)
end

-- 闭关修炼
TimerFunc[13] = function(sysarg)
	return on_bgxl_handle_reward_timer_cb(sysarg)
end

-- 巨魔之巢
TimerFunc[14] = function(sysarg)
	return on_jmzc_handle_timer(sysarg)
end

-- 城主活动泡点
TimerFunc[15] = function(sysarg)
	return on_pd_handle_timer(sysarg)
end

-- 武林争霸泡点
TimerFunc[16] = function(sysarg)
	return on_wlzb_handle_reward_timer_cb(sysarg)
end


-- 阵营战
TimerFunc[17] = function(sysarg)
	return on_zyzPaoDian_time_cd(sysarg)
end

--[[
function publicTest_buyTitle(sysarg, btn)
	btn = tonumber(btn)
	if btn ~= 1 then return end
	
	_PublicTestBuyTitleGift(sysarg)	
end
--]]